/*
 * TCSS 360 - Autumn 2011
 * Group2: ManuscriptPR
 *
 * User class
 * Author: Tony Butterfield
 */

package user;

import java.util.List;


/**
 * a class containing user data and a collection of conference roles. 
 * @author Tony Butterfield, and Christopher Yeaman(equals method)
 * @version 11/23/2011
 */
public class User
{
  // INSTANCE VARIABLES ***********************************
  /** user's first name. */
  private String my_first_name;

  /** user's last name.  */
  private String my_last_name;
 
  /** collection of user's conference roles.  */
  private ConfMembershipCollection my_conference_roles;
  

  // CONSTRUCTORS *****************************************
  /**
   * constructor for User class.
   * 
   * @param the_first_name String containing user's first name.
   * @param the_last_name String containing user's last name.
   ******************************************************** 
   * @requires the_first_name = String && the_last_name = String 
   * @ensures my_first_name = the_first_name && my_last_name = the_first_name
   *    && my_conference_roles = an empty Map 
   */
  public User(final String the_first_name, final String the_last_name)
  {    
    setFirstName(the_first_name);
    setLastName(the_last_name);
    my_conference_roles = new ConfMembershipCollection();
  }

  
  // ACCESSORS ********************************************
  /** 
   * get user's last name. 
   * @return String containing user's last name.
   */
  public String getLastName()
  {
    return my_last_name;
  }
  
  /** 
   * get user's first name. 
   * @return String containing user's first name.
   */
  public String getFirstName()
  {
    return my_first_name;
  }
    
  
  
  /**
   * get a list of all conference names the user has a role in.
   * @return List<String> of sorted conference names
   ********************************************************
   * @ensures method returns a sorted List<String>
   */
  public List<String> getAllConferenceNames()
  {
    return my_conference_roles.getAllConferenceNames();
  }
  
  /**
   * get reference to a conference that the user has a role in.
   * @param the_conference_name String with the conferences name
   * @return Conference that matches, or null
   ********************************************************
   * @requires the_conference_name = String
   * @ensures method returns a Conference or null if no matches
   */
  public Conference getConference(final String the_conference_name)
  {
    return my_conference_roles.getConference(the_conference_name);
  }
  
  
  /**
   * get the user's assigned role for a given conference.
   * @param the_conference Conference to query
   * @return Role for that conference
   ********************************************************
   * @requires the_conference = Conference
   * @ensures method returns Role enumeration or null if no match
   */
  public Role getRole(final Conference the_conference)
  {
    return my_conference_roles.getConferenceRole(the_conference.getConferenceName());
  }
  
  
  /**
   * get the user's assigned role for a given conference.
   * @param the_conference_name String name of conference
   * @return Role associated with that conference
   ********************************************************
   * @requires the_conference_name = String
   * @ensures method returns Role enumeration or null if no match
   */
  public Role getRole(final String the_conference_name)
  {
    return my_conference_roles.getConferenceRole(the_conference_name);
  }
  
  // MUTATORS *********************************************
  /**
   * sets the users first name.
   * @param the_first_name String containing first name
   * @throws NullPointerException()
   * ******************************************************** 
   * @requires the_first_name = String
   * @ensures my_first_name = the_first_name
   */
  private void setFirstName(final String the_first_name)
  {
    if (the_first_name != null)
    {
      my_first_name = the_first_name;
    }
    else
    {
      throw new NullPointerException();
    }
  }
  
  /**
   * sets the users last name.
   * @param the_last_name String containing last name
   * ******************************************************** 
   * @requires the_last_name = String
   * @ensures my_last_name = the_last_name
   */
  private void setLastName(final String the_last_name)
  {
    if (the_last_name != null)
    {
      my_last_name = the_last_name;
    }
    else
    {
      throw new NullPointerException();
    }
  }


  /**
   * adds a new Conference/Role pair to the map.
   * @param the_conference Conference being added to the map
   * @param the_role Role enumerated value being paired with the Conference
   ********************************************************
   * @requires the_conference = Conference && the_role = Role
   * @ensures the Conference/Role pair is added to the map
   */
  public void addConferenceRole(final Conference the_conference, final Role the_role)
  {
    if (the_conference != null && the_role != null)
    {
      my_conference_roles.addMembership(the_conference, the_role);
    }
    else
    {
      throw new NullPointerException();
    }
  }
    
  
  // METHODS **********************************************
  /** 
   * checks to see if there is a conference with the given name in the user's list of 
   * conferences.
   * @param the_conference_name String being searched for
   * @return boolean result of query
   ********************************************************
   * @requires the_conference_name = String
   * @ensures method returns TRUE if there is a match, else FALSE
   */
  public boolean isMember(final String the_conference_name)
  {    
    return my_conference_roles.isMember(the_conference_name);
  }

  /**
   * get the user's full name in "Last, First" form.
   * @return String containing the user's formatted name
   ********************************************************
   * @ensures method returns a formatted name string
   */
  public String getFullName()
  {
    return getLastName() + ", " + getFirstName();
  }  
  
  /**
   * toString method.
   * @return String fullname
   */
  public String toString()
  {
    return getFullName();
  }
}
